<template>
  <div>
    <component
      :is="FormCard"
      :enum-name="enumName"
      @render="render"
    />
    <component
      :is="TableCard"
      ref="TableCard"
      :enum-name="enumName"
      :btn-data="btnData"
      @detailOwner="detailOwner"
      @render="render"
      @updateOwner="updateOwner"
      @delOwner="delOwner"
    />
  </div>
</template>

<script>
import FormCard from '@/components/FormCard'
import TableCard from '@/components/TableCard'
import { getPageOwner, deleteOwner, getOwner, getOwnerDetail } from '@/api/owner'

export default {
  components: {
    FormCard,
    TableCard
  },
  data() {
    return {
      TableCard,
      FormCard,
      enumName: 'owner',
      btnData: { name: '增加货主', show: true, click: 1 },
      data: {
        id: '',
        size: 10,
        descs: 'createTime',
        current: 1
      }
    }
  },
  computed: {
  },
  async mounted() {
    await this.render()
  },
  methods: {
    // 我是查看详情
    async detailOwner(value) {
      this.$router.push(`/commerce/owner/details/${value}`)
      await getOwner(value)
      await getOwnerDetail(value)
    },
    // '我是修改'
    updateOwner(value) {
      this.$router.push(`/commerce/owner/addnew/${value}`)
    },
    // 删除方法
    async  delOwner(ids) {
      try {
        await this.$confirm('确定要删除吗')
        await deleteOwner([ids])
        this.$message.success('删除成功咯')
        this.render()
      } catch (error) {
        this.$message.warning('取消删除咯')
      }
    },
    // async ownerSearch(params) {
    //   this.render(params)
    // },
    // 渲染页面方法（获取数据）
    async  render(params = {}) {
      this.data = { ...this.data, ...params }
      const { data } = await getPageOwner({ ...this.data, ...params })
      this.$refs.TableCard.basicData = data.records
      this.$refs.TableCard.total = +data.total
      this.$refs.TableCard.size = +data.size
      this.$refs.TableCard.current = +data.current
    }
  }
}
</script>

<style>
</style>
